<?php

namespace App\Services;

use Illuminate\Support\Facades\Log;

class OrderService
{
    public $id;
    public $name;

    public function __construct($id,$name)
    {
        $this->id = $id;
        $this->name = $name;
    }

    /**
     * 是否支付成功
     */
    public function queryPayState(){
        $rand = rand(1,5);
        Log::info('队列执行了！');
        $info = 'id 为'.$this->id.' 的'.$this->name.'用户成功支付了！';
        if($rand == 2){
            Log::info($info);
        }else{
            Log::info($info);
//            throw new Exception("pay failed");
            //失败时走队列失败任务、或者是在队列中直接再启动一个延迟队列
        }
    }

    /**
     * 是否充值成功
     */
    public function orderVipBuy(){
        $rand = rand(1,5);
        Log::info('队列执行了2！');
        $info = 'id 为'.$this->id.' 的'.$this->name.'用户充值会员成功了！';
        if($rand == 3){
            Log::info($info);
        }else{
            Log::info($info);
//            throw new Exception("buy failed");
        }
    }
}
